
package org.vasil.jouikov.synchro

//import groovy.xml.StreamingMarkupBuilder


def webConnect = { body ->

    try {
        def connection = "http://localhost:8080/Synchro/items".toURL().openConnection()
        connection.setRequestProperty("Content-Type", "application/xml")
        connection.setRequestMethod("POST")
        connection.doOutput = true

        connection.outputStream.withWriter { writer ->  writer << body }

        def response = connection.inputStream.withReader { reader -> reader.text }

        if(connection.responseCode == 200 || connection.responseCode == 201) {
            return [status: "OK", body: response]
        }
        return [status: "ERR", body: "${connection.responseCode} : ${connection.responseMessage}"]
    }
    catch(error) {
        return [status: "ERR", body: error]
    }
}

def name='vasil'

println "Hello $name!"

def result = webConnect(XmlTest.DESC712000514_31)
println "result2=${result.body}"


